package com.itheima.moviedemo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class MovieSystem {
    //创建一个集合来存放对象
    ArrayList<Movie> Movies = new ArrayList<>();
    Scanner sc = new Scanner(System.in);

    public MovieSystem(ArrayList<Movie> movies) {
        Movies = movies;
    }

    //上架电影
    public void addMovie(){
        Movie movie = new Movie();
        System.out.println("======电影添加=======");
        System.out.println("请输入要添加的电影的信息:");
        System.out.println("请输入电影编号:");
        movie.setId(sc.nextInt());
        System.out.println("请输入电影名称:");
        movie.setName(sc.next());
        System.out.println("请输入电影价格:");
        movie.setPrice(sc.nextDouble());
        System.out.println("请输入电影评分:");
        movie.setScore(sc.nextDouble());
        System.out.println("请输入导演:");
        movie.setDirector(sc.next());
        System.out.println("请输入主演:");
        movie.setActor(sc.next());
        System.out.println("请输入简介:");
        movie.setInfo(sc.next());
        Movies.add(movie);
        System.out.println("添加成功！");

    }
    //查询电影
    public void getMovieById(String Id){
        //使用增强for循环
        for (Movie movie : Movies) {
            if(movie.getId() == Integer.parseInt(Id)){
                //展示电影的全部信息
                System.out.println("电影名称:"+movie.getName());
                System.out.println("电影价格:"+movie.getPrice());
                System.out.println("电影评分:"+movie.getScore());
                System.out.println("导演:"+movie.getDirector());
                System.out.println("主演:"+movie.getActor());
                System.out.println("简介:"+movie.getInfo());
                return;
            }
            System.out.println("没有此编号的电影！");
        }
    }

    //下架电影
    public void removeMovieByActor(String Actor){
        System.out.println("======下架电影=======");
        //用迭代器irerator
        Iterator<Movie> it = Movies.iterator();
        while (it.hasNext()){
            Movie movie = it.next();
            if(movie.getActor().equals(Actor)){
                System.out.println("下架成功！");
                it.remove();
                return;
            }else{
                System.out.println("没有此演员扮演的电影");
            }
        }
    }


}
